package com.heima.wemedia.controller.v1;


import com.heima.api.wemedia.WmMaterialControllerApi;
import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {
    @Resource
    private WmMaterialService materialService;

    /**
     * @param multipartFile 上传的文件对象
     * @return 上传结果
     * @Description 上传图片
     */
    @PostMapping("/upload_picture")
    @Override
    public ResponseResult uploadPicture(MultipartFile multipartFile) {
        return materialService.uploadPicture(multipartFile);
    }

    /**
     * @param dto 素材分页查询对象
     * @return 查询结果
     * @Description 素材列表
     */
    @PostMapping("/list")
    @Override
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return materialService.findList(dto);
    }

    /**
     * @param id 删除图片对象id
     * @return 删除结果
     * @Description 删除图片
     */
    @GetMapping("/del_picture/{id}")
    @Override
    public ResponseResult delPicture(@PathVariable("id") Integer id) {
        return materialService.delPicture(id);
    }

    /**
     * @param id 图片文件id
     * @return 更新结果
     * @Description 取消收藏
     */
    @GetMapping("/cancel_collect/{id}")
    @Override
    public ResponseResult cancelCollectionMaterial(@PathVariable("id") Integer id) {
        return materialService.updateStatus(id, WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

    /**
     * @param id 图片文件id
     * @return 更新结果
     * @Description 收藏图片
     */
    @GetMapping("/collect/{id}")
    @Override
    public ResponseResult collectionMaterial(@PathVariable("id") Integer id) {
        return materialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }

}